import LogUtil, { LOG_LEVEL } from "../utils/LogUtil";
import { SingletonTemplet } from "../utils/SingletonTemplet";
let serverType = 0; //开发
// serverType = 1; //测试
// serverType = 2; //外网
export default class GlobalData extends SingletonTemplet{
	/**前端 发布的版本号*/
	private _appVersion:string = '';
	/**前端 发凪时对就git的版本号*/
	private _gitVersion:string = '';
	/**热更配置柳取的地址*/
	private _configUrl:string = '';
	/**后端服务地址*/
	private _appHttpHost:string = 'http://127.0.0.1:8080"';
	
	private _reqApiInterceptArr :Array<String> = [];
	public init(){
		switch (serverType){
			case 0:
				this._appHttpHost = "/api/";//"https://www.bestxinrui.com:8040/";
				break;
			case 1:
				this._appHttpHost = "http://127.0.0.1:8080/";
				break;
			case 2:
				this._appHttpHost = "http://127.0.0.1:8080/";
				break;
			default:
				break;
		}
		//请求事件拦截器
		this._reqApiInterceptArr.forEach((apiName,index,arr)=>{
			uni.addInterceptor(apiName.toString(),{
				invoke: (result) => {
					LogUtil.log(LOG_LEVEL.WARN,'GlobalData',"请求被拦截")
					return false;
				}
			})
		})
		//未登陆用户tabbar跳转拦截器
		uni.addInterceptor('switchtab',{
			invoke: (result) => {
				if(result.url!= 'pages/index/index'){
					//跳转到登陆
					uni.redirectTo({
						url:'pages/index/index'
					})
					return false;
				}else{
					return true;
				}
			}
		})
	}	
	public setAppVersion(version:string){
		this._appVersion = version;
	}
	public getAppVersion():string {
		return this._appVersion;
	}
	public setGitVersion(version:string){
		this._gitVersion = version;
	}
	public getGitVersion():string {
		return this._gitVersion;
	}
	public setConfigUrl(configUrl:string){
		return this._configUrl = configUrl;
	}
	public getConfigUrl():string{
		return this._configUrl;
	}
	public getAppHttpHost(){
		return this._appHttpHost;
	}
	
}
export const globlData = GlobalData.getInstance();